<?php

namespace App\Models;

use App\Admin\Repositories\Receipt as RepositoriesReceipt;
use Dcat\Admin\Traits\HasDateTimeFormatter;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

class Receipt extends Model
{
    use SoftDeletes;
    use HasDateTimeFormatter;
    protected $table = 'receipt';


    protected $hidden = ['deleted_at'];

    protected $fillable = [
        'user_id',
        'order_id',
        'receipt_info_id',
        'status',
        'total_money',
        'express_name',
        'express_number',
        'express_img',
        'type',
        'header',
        'company_addr',
        'company_phone',
        'bank_name',
        'bank_number',
        'tax_type',
        'tax_user_id',
        'tax_cert',
        'receive_user',
        'receive_mobile',
        'receive_addr',
        'remark',
    ];

    public function getKeyName()
    {
        return 'id';
    }

    /**
     * @return BelongsTo
     */
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function receiptInfo()
    {
        return $this->hasOne(ReceiptInfo::class, 'id', 'receipt_info_id');
    }

    public function getTaxTypeTextAttribute($value)
    {
        return RepositoriesReceipt::getTaxType($value);
    }

    public function getTypeTextAttribute($value)
    {
        return RepositoriesReceipt::getInvoiceType($value);
    }
}
